﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public sealed class WaitLoadFont : CustomYieldInstruction
    {
        private FontCache fontcache;
        public Font LoadedObject { get; private set; }
        public string Error { get; private set; }

        public WaitLoadFont(FontCache cache)
        {
            this.fontcache = cache;
        }

        public override bool keepWaiting
        {
            get
            {
                if (!string.IsNullOrEmpty(this.fontcache.Error))
                {
                    this.Error = this.fontcache.Error;
                    return false;
                }
                if (this.fontcache.IsNotNull())
                {
                    this.LoadedObject = this.fontcache.GetObject();
                    return false;
                }
                return true;
            }
        }
    }
}

